﻿@page "/UpdateBook/{Id:int?}"
@using Carlife.Inf;
@using ICarlifeService;
@using Models;
@using Microsoft.EntityFrameworkCore;
@using Models.Authority;
@inject IDbContextFactory<CarlifeDbcontext> dbFactory;
@inject IRolesService ibase;
@inject NavigationManager NavigationManager
@inject IJSRuntime jsRuntime
<h3>@UpdBook</h3>
<PageTitle>角色修改</PageTitle>
<EditForm Model="role" OnSubmit="@HandSubMit">
    <div>
        <p>
            父级角色ID ：
            <input @bind="@role.Parent_id" type="number"></input>
        </p>
        <p>
            账户：
            <input @bind="@role.Account" type="text"></input>
        </p>

        <p>
            名称：
            <input @bind="@role.RoleName" type="text"></input>
        </p>

        <p>
            角色描述：
            <textarea @bind="@role.Description"></textarea>
        </p>
        <button type="submit">@UpdBook</button>
    </div>
</EditForm>
@code {
    private string UpdBook = "修改";
    [Parameter]
    public int? Id { get; set; }
    private Roles role = new Roles();

    protected override async Task OnInitializedAsync()
    {
        if (Id.HasValue)
        {
            role = ibase.GetRoleByid(Id.Value);
            UpdBook = "编辑";
        }
        await base.OnInitializedAsync();
    }
    private async void HandSubMit()
    {
        role.IsData = true;
        if (Id.HasValue)
        {
            ibase.GetRoleUpdate(role);
            await jsRuntime.InvokeAsync<string>("alert", "编辑成功 !");
            NavigationManager.NavigateTo($"BookIndex");
        }
        else
        {
            await jsRuntime.InvokeAsync<string>("alert", "编辑失败 !");
        }
    }
}
